<template>
    <div style="height:100%">
      <v-navbar :navinfo="navinfo"></v-navbar>
      <div  :style="{'height':slide_h*0.24+'px','min-height':slide_h*0.24+'px','padding-top':slide_h*0.1+'px'}"class="text-center title24 ">
        <div  v-if="this.$store.getters.getConfig()!=null&&this.$store.getters.getConfig().webLogo">
          <img style="height:84px;width:84px;"  :src="proAPI.RESOURCE_URL+this.$store.getters.getConfig().webLogo"/>
          <div class="title24">{{this.$store.getters.getConfig().webName}}</div>
        </div>
      </div>
      <van-row id="loginView">
        <van-col offset="1" span="22">
          <van-field
            v-model="ruleForm.userName"
            clearable
            placeholder="请输入用户名"
          />
          <div style="height:10px;"></div>
          <van-field
            v-model="ruleForm.password"
            type="password"
            clearable
            placeholder="请输入密码"
          />
          <!--<van-cell-group>-->
            <!--<van-field-->
              <!--v-model="ruleForm.rand"-->
              <!--center-->
              <!--clearable-->
              <!--placeholder="请输入验证码"-->
              <!--@click-icon="changeCode()"-->
            <!--&gt;-->
              <!--<van-button class="transparent border0 cursor " slot="icon" size="small" ><img class="captcha" :src="captcheurl"/></van-button>-->
            <!--</van-field>-->
          <!--</van-cell-group>-->
          <div class="p-tb5"></div>
          <div class="p-lr10">
            <van-button @click="submitForm()"  size="large" type="primary">立 即 登 陆</van-button>
          </div>
          <div class="p-lr10 text-right">
            <div class="p-tb10"></div>
            <span @click="toSign()" class="cursor title14" >立 即 注 册</span>
          </div>
        </van-col>
      </van-row>
    </div>
</template>
<script type="es6">
  const navbar = () =>
    import ('@/components/header/NavBar')
  export default {
    components: {
      'v-navbar': navbar,
    },
    data() {
      return {
        visible:false,
        navinfo: {title: '登陆', leftText: '',leftIcon:'', leftLink:'', rightText: '',rightIcon:'',rightLink:''},
        captcheurl: '',
        ruleForm: {
          userName: '',
          password: '',
          // rand: ''
        },
        slide_h:(window.document.body.offsetHeight)
      }
    },
    methods: {
      submitForm(formName) {
        var m = {
          userName: this.ruleForm.userName,
          password: this.proUtil.md5(this.proUtil.md5(this.ruleForm.password)),
          // rand: this.ruleForm.rand
        };
        this.$store.commit("saveLoadingMap",{"target":this.proAPI.URLS.login,lock:1,text:"正在登陆....",background:"rgba(0,0,0,0.6)"});
        this.proAPI.postJson(this.proAPI.URLS.login, m).then((res) => {
          this.$store.state.CSRFToken = res.data.CSRFToken;
          localStorage.setItem(process.env.PROJECT_NAME+"CSRFToken",res.data.CSRFToken);
          this.$store.commit("saveToken", res.data.token);
          console.log(this.$store.getters.getValForKey("beforeLoginUrl"));
          var beforeLoginUrl = this.$store.getters.getValForKey("beforeLoginUrl");
          this.proUtil.msgSuccess("登陆成功");
          this.$store.dispatch("init");//重新获取客户端的用户信息
          if (!this.proUtil.isNull(beforeLoginUrl)) {
            localStorage.removeItem("beforeLoginUrl");
            localStorage.removeItem("beforeLoginTime");
            //计算之前存储的登录之前的页面是否小于10分钟
            if (this.proUtil.isNull(beforeLoginUrl) || (new Date().getTime() - (this.$store.getters.getValForKey("beforeLoginTime"))) > 600000) {
              console.log(1222222);
              this.$router.replace("/home");
            } else {
              console.log(233333333);
              this.$router.replace("/home");
              // this.$router.replace(beforeLoginUrl);
            }
          } else {
            this.$router.replace("/home");
          }

        });
      },
      changeCode() {
        this.captcheurl = process.env.BASE_API + this.proAPI.URLS.getLoginCaptcha + "?t=" + new Date().getTime()
      },
      toSign(){
        this.$router.push("/sign");
      }
    },
    mounted() {
      setTimeout(()=>{
        this.changeCode();
      },500)
      this.$nextTick(()=>{
        this.$store.commit("clearLoadingMap");
        this.visible=true;
      })
    }
  }
</script>
<style scoped>
  .captcha {
    vertical-align: middle;
    width:84px;
    height:100%;
  }
</style>
